package spring.data.specification.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * 描述: TODO:
 * 包名: spring.data.specification.entity.
 * 作者: barton.
 * 日期: 16-7-2.
 * 项目名称: spring-data
 * 版本: 1.0
 * JDK: since 1.8
 */
@Entity
@Table(name = "SYS_USER")
public class SysUser implements Serializable {
  private static final long serialVersionUID = 1L;

  public enum UserStatus {
    NORMAL, LOCKED, DISMISS, DELETE;
  }

  @Id
//	@GeneratedValue(strategy = GenerationType.TABLE)
  @Column(name = "USER_ID")
  private String id;

  private String username;
  @JsonIgnore
  private String password;

  @ManyToOne(fetch = FetchType.EAGER)
  @JoinColumn(name = "ORGANIZATION_ID")
  private SysOrganization sysOrganization;

  @OneToOne(fetch = FetchType.EAGER)
  @JoinColumn(name = "USER_ID")
  private Manager manager;

  @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  @JoinColumn(name = "USER_ID")
  private SalesMan salseMan;

  @Enumerated(EnumType.ORDINAL)
  private UserStatus status = UserStatus.NORMAL;

  @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  @JoinTable(name = "SYS_USERS_ROLES", joinColumns = @JoinColumn(name = "USER_ID"), inverseJoinColumns = @JoinColumn(name = "ROLE_ID"))
  private Set<SysRole> sysRoles = new HashSet<>();

  public SysUser() {
  }
;
  public SysUser(String username, String password) {
    this.username = username;
    this.password = password;
  }

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public UserStatus getStatus() {
    return status;
  }

  public void setStatus(UserStatus status) {
    this.status = status;
  }


  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public Set<SysRole> getSysRoles() {
    return sysRoles;
  }

  public void addSysRole(SysRole sysRoles) {
    this.sysRoles.add(sysRoles);
  }

  public void setSysRoles(Set<SysRole> sysRoles) {
    this.sysRoles = sysRoles;
  }

  public SysOrganization getSysOrganization() {
    return sysOrganization;
  }

  public void setSysOrganization(SysOrganization sysOrganization) {
    this.sysOrganization = sysOrganization;
  }

  public Manager getManager() {
    return manager;
  }

  public void setManager(Manager manager) {
    this.manager = manager;
  }

  public SalesMan getSalseMan() {
    return salseMan;
  }

  public void setSalseMan(SalesMan salseMan) {
    this.salseMan = salseMan;
  }

  @Override
  public String toString() {
    return "User [id=" + id + ", username=" + username + ", password="
     + password + ", status=" + status + "]";
  }
}
